package com.gopay.bis.gdb.ebank.impl;

import com.gopay.bis.common.util.BankLogUtils;
import com.gopay.bis.gdb.ebank.gfbank.payment.merchant.PayCfg;
import com.gopay.bis.gdb.ebank.operation.GdbB2cQuery;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.BaseMessage;
import com.gopay.common.domain.bank.gdb.ebank.GdbB2cMessage;
import com.gopay.common.exception.GopayException;
import com.gopay.remote.bank.ICertHelper;
import com.gopay.remote.bank.businesses.BankService;

/**
 * 广发银行B2C网关支付
 * 
 * @GdbB2cBankServiceImpl.java
 * @author zhengxue
 * @2014-11-13 上午9:26:20 www.gopay.com.cn Inc.All rights reserved.
 */
public class GdbB2cBankServiceImpl implements BankService {
    private ICertHelper gdbB2cCertHelper;
    private GdbB2cQuery gdbB2cQuery;

    @Override
    public Object sign(BaseMessage msg) throws GopayException {
        try {
        	GdbB2cMessage message = (GdbB2cMessage) msg;
            String merchid = message.getMerID();
            String orderid = message.getBankOrderId();
            String amount = message.getAmount().toString();
            String gdbURL = PayCfg.getValue("gfbankpaygateurl"); // 广东发展银行网关支付地址
            String returl = message.getPayRuturnUrl(); // 接收支付结果通知地址

            String signResult = gdbB2cCertHelper.sign(message);
            // 组装请求银行参数
			gdbURL = gdbURL + "?merchid=" + merchid + "&orderid=" + orderid
					+ "&amount=" + amount + "&sign=" + signResult + "&returl="
					+ returl + "&mccCode=" + message.getMccCode()
					+ "&goodstype=" + message.getGoodsType() + "&sendWay="
					+ message.getSendWay() + "&productName="
					+ message.getProductName() + "&secondMerName="
					+ message.getSecondMerName() + "&websiteName="
					+ message.getWebsiteName() + "&netAddress="
					+ message.getNetAddress() + "&channel="
					+ message.getChannel() + "&domainname="
					+ message.getDomainName()+ "&customerip=192.168.10.363";
            return gdbURL;
        } catch (Exception e) {
            BankLogUtils.printB2CSignExceptionLog(msg, e);
            throw new GopayException(ProcCodeConstants.PROC_CODE_100E6029);
        }

    }

    @Override
    public Object verify(BaseMessage msg) throws GopayException {
        return gdbB2cCertHelper.verify(msg);
    }

    @Override
    public Object query(Object obj) throws GopayException {
        GdbB2cMessage message = (GdbB2cMessage) obj;
        return gdbB2cQuery.query(message);
    }
    
    @Override
	public Object dayend(Object obj) throws GopayException {
		// TODO Auto-generated method stub
		return null;
	}

    public void setGdbB2cCertHelper(ICertHelper gdbB2cCertHelper) {
        this.gdbB2cCertHelper = gdbB2cCertHelper;
    }

    public void setGdbB2cQuery(GdbB2cQuery gdbB2cQuery) {
        this.gdbB2cQuery = gdbB2cQuery;
    }

	@Override
	public Object refund(Object obj) throws GopayException {
		// TODO Auto-generated method stub
		return null;
	}

}
